// components/community-share/community-share.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    communityshare:Object
  },
  /**
   * 组件的初始数据
   */
  data: {
    content:[
        {url:'https://img0.baidu.com/it/u=2940901229,1294457019&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=313'},
        {url:'https://img0.baidu.com/it/u=335417749,192676620&fm=253&fmt=auto&app=138&f=JPEG?w=658&h=439'},
        {url:'https://img0.baidu.com/it/u=2907260141,3240414659&fm=253&fmt=auto&app=138&f=JPEG?w=658&h=411'},
        {url:'https://img1.baidu.com/it/u=4216761644,15569246&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'},
        {url:'https://img1.baidu.com/it/u=4216761644,15569246&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500'},
    ],
  },
  onShow: function () {
    console.log('communityshare.address.image');
  },
  lifetimes:{
    attached(){
      function friendlyFormatTime(stringTime) {
        let str = stringTime;
        //将字符串转换成时间格式
        let timePublish = new Date(str);
        let timeNow = new Date();
        let minute = 1000 * 60;
        let hour = minute * 60;
        let day = hour * 24;
        let month = day * 30;
        let year = month * 12;
        let diffValue = timeNow - timePublish;
        let diffMonth = diffValue / month;
        let diffWeek = diffValue / (7 * day);
        let diffDay = diffValue / day;
        let diffHour = diffValue / hour;
        let diffMinute = diffValue / minute;
        let diffYear = diffValue / year;
        let result = null
        if (diffValue < 0) {
         result = "刚刚";
        } else if (diffYear > 1) {
         result = parseInt(diffYear) + "年前";
        } else if (diffMonth > 1) {
         result = parseInt(diffMonth) + "月前";
        } else if (diffWeek > 1) {
         result = parseInt(diffWeek) + "周前";
        } else if (diffDay > 1) {
         result = parseInt(diffDay) + "天前";
        } else if (diffHour > 1) {
         result = parseInt(diffHour) + "小时前";
        } else if (diffMinute > 1) {
         result = parseInt(diffMinute) + "分钟前";
        } else {
         result = "刚刚";
        }
        return result;
     };
      console.log(friendlyFormatTime(this.data.communityshare.neighborhoodSharingDto.createTime));
      this.setData({
        'communityshare.neighborhoodSharingDto.createTime':friendlyFormatTime(this.data.communityshare.neighborhoodSharingDto.createTime)
      })
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    
  }
})
